package cz.cvut.fit.web.nakupniSeznam.dao;

import java.util.List;

import javax.persistence.NoResultException;
import javax.persistence.Query;

import cz.cvut.fit.web.nakupniSeznam.data.Item;

public class ItemDAO extends GenericDAO<Item> {

	private static ItemDAO instance = null;

	public static ItemDAO getInstance() {
		if (instance == null) {
			instance = new ItemDAO();
		}
		return instance;
	}

	@Override
	protected String getAllQueryName() {
		return "item.getAll";
	}

	@Override
	protected Class<Item> getEntityClass() {
		return Item.class;
	}

	@SuppressWarnings("unchecked")
	public List<Item> getByList(Long id) {
		Query q = this.em.createNamedQuery("item.getByList");
		q.setParameter("listId", id);

		try {
			return (List<Item>) q.getResultList();
		} catch (NoResultException ex) {
			return null;
		}
	}

}
